#include"sort.h"

void swap(int* x, int* y)
{
	int tmp = *x;
	*x = *y;
	*y = tmp;
}

int _qusort(int* arr, int left, int fight)
{
	int key = left;
	left++;
	while (left <= fight)
	{
		while (left <= fight && arr[fight] > arr[key])
		{
			fight--;
		}
		while (left <= fight && arr[left] < arr[key])
		{
			left++;
		}

		if (left <= fight)
		{
			swap(&arr[left], &arr[fight]);
		}
	}
	swap(&arr[fight], &arr[key]);
	return fight;

}

void qusort(int* arr, int left, int fight)
{
	if (left >= fight)
	{
		return;
	}

	int key = _qusort(arr, left, fight);

	qusort(arr, left, key - 1);

	qusort(arr, key + 1, fight);
}